package com.ruoyi.part.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.part.domain.DmsPartsDelivery;
import com.ruoyi.part.service.IDmsPartsDeliveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 零件发运Controller
 * 
 * @author liuchuanfa
 * @date 2024-03-17
 */
@RestController
@RequestMapping("/part/delivery")
public class DmsPartsDeliveryController extends BaseController
{
    @Autowired
    private IDmsPartsDeliveryService dmsPartsDeliveryService;

    /**
     * 查询零件发运列表
     */
    @PreAuthorize("@ss.hasPermi('part:delivery:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsPartsDelivery dmsPartsDelivery)
    {
        startPage();
        List<DmsPartsDelivery> list = dmsPartsDeliveryService.selectDmsPartsDeliveryList(dmsPartsDelivery);
        return getDataTable(list);
    }

    /**
     * 导出零件发运列表
     */
    @PreAuthorize("@ss.hasPermi('part:delivery:export')")
    @Log(title = "零件发运", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsPartsDelivery dmsPartsDelivery)
    {
        List<DmsPartsDelivery> list = dmsPartsDeliveryService.selectDmsPartsDeliveryList(dmsPartsDelivery);
        ExcelUtil<DmsPartsDelivery> util = new ExcelUtil<DmsPartsDelivery>(DmsPartsDelivery.class);
        util.exportExcel(response, list, "零件发运数据");
    }

    /**
     * 获取零件发运详细信息
     */
//    @PreAuthorize("@ss.hasPermi('part:delivery:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dmsPartsDeliveryService.selectDmsPartsDeliveryById(id));
    }

    /**
     * 新增零件发运
     */
    @PreAuthorize("@ss.hasPermi('part:delivery:add')")
    @Log(title = "零件发运", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsPartsDelivery dmsPartsDelivery)
    {
        return toAjax(dmsPartsDeliveryService.insertDmsPartsDelivery(dmsPartsDelivery));
    }

    /**
     * 修改零件发运
     */
//    @PreAuthorize("@ss.hasPermi('part:delivery:edit')")
    @Log(title = "零件发运", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsPartsDelivery dmsPartsDelivery)
    {
        return toAjax(dmsPartsDeliveryService.updateDmsPartsDelivery(dmsPartsDelivery));
    }

    /**
     * 删除零件发运
     */
    @PreAuthorize("@ss.hasPermi('part:delivery:remove')")
    @Log(title = "零件发运", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsPartsDeliveryService.deleteDmsPartsDeliveryByIds(ids));
    }
}
